from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.
class Users(AbstractUser):
    mobile = models.CharField(max_length=11, verbose_name="手机号")
    agree = models.BooleanField(verbose_name="同意协议")

    class Meta:
        db_table = "user"
        verbose_name = "用户"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


# 地址模型类
class Address(models.Model):
    receiver = models.CharField(max_length=30, verbose_name="收件人")
    receive_mobile = models.CharField(max_length=11, verbose_name="手机号")
    receive_addr = models.CharField(max_length=100, verbose_name="收货地址")
    is_default = models.BooleanField(verbose_name="是否默认", default=False)
    user = models.ForeignKey(to=Users, on_delete=models.CASCADE, verbose_name="用户")

    class Meta:
        db_table = "address_t"
        verbose_name = "收获地址"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.receiver + " " + self.receive_mobile + " " + self.receive_addr
